package cn.edu.shu.wechat.webservice.api.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.shu.wechat.core.bean.EventType;
import cn.edu.shu.wechat.core.menu.Menu;
import cn.edu.shu.wechat.core.menu.MenuButton;
import cn.edu.shu.wechat.core.menu.MenuManager;

@Controller
@RequestMapping("/menu")
public class MenuController {
	@Autowired
	private MenuManager  menuManager;
	
	@RequestMapping("/create")
	public @ResponseBody String createMenu(){
		menuManager.create(getMenu());
		return "create menu success!";
	}
	public Menu getMenu(){
		Menu menu=new Menu();
		MenuButton topButton1=new MenuButton();
		topButton1.setName("发布书籍");
		topButton1.setType(EventType.view);
		topButton1.setUrl("http://sofine.space/wechat/published-books.html");
		
		MenuButton topButton2=new MenuButton();
		topButton2.setName("搜索书籍");
		topButton2.setType(EventType.view);
		topButton2.setUrl("http://sofine.space/wechat/search-books.html");
		
		MenuButton topButton3=new MenuButton();
		topButton3.setName("关于我们");
		
		MenuButton secondLevelButton1=new MenuButton();
		secondLevelButton1.setName("官网");
		secondLevelButton1.setType(EventType.view);
		secondLevelButton1.setUrl("http://sofine.space/wechat/index.html");
		
		MenuButton secondLevelButton2=new MenuButton();
		secondLevelButton2.setName("帮助");
		secondLevelButton2.setType(EventType.view);
		secondLevelButton2.setUrl("http://sofine.space/wechat/help.html");
		
		MenuButton secondLevelButton3=new MenuButton();
		secondLevelButton3.setName("关于");
		secondLevelButton3.setType(EventType.view);
		secondLevelButton3.setUrl("http://sofine.space/wechat/about-us.html");
		List<MenuButton> topButton3List=new ArrayList<MenuButton>();
		topButton3List.add(secondLevelButton1);
		topButton3List.add(secondLevelButton2);
		topButton3List.add(secondLevelButton3);
		topButton3.setSubButton(topButton3List);
		List<MenuButton> allButtons=new ArrayList<MenuButton>();
		allButtons.add(topButton1);
		allButtons.add(topButton2);
		allButtons.add(topButton3);
		menu.setButton(allButtons);
		return menu;
	}

}
